home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Environments / Oberon⁄F™ 1.2 / Preinstalled version / Obx / Mod / MacEditor (.txt) < prev    next >
Encoding:
Oberon Document  |  1996-07-08  |  22.1 KB  |  613 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Helvetica
  16. TextRulers.StdRulerDesc
  17. TextRulers.RulerDesc
  18. TextRulers.StdStyleDesc
  19. TextRulers.StyleDesc
  20. TextRulers.AttributesDesc
  21. Helvetica
  22. DevCommanders.StdViewDesc
  23. DevCommanders.ViewDesc
  24. Helvetica
  25. Helvetica
  26. MODULE ObxMacEditor;    (* sample Macintosh application mf/od/cp *)
  27. (* This sample text editor shows how to use Oberon/F to develop a standalone Mac application.
  28.     Some parts are taken from Inside Macintosh: Toolbox Essentials, so you need to look
  29.     there, if you have some specific questions about the code.
  30.     Click the following commands to compile and link the application (no linker is available in
  31.     the educational version of Oberon/F):
  32.  DevCompiler.Compile
  33.  DevLinker.Link ":Obx:MacEditor" +ObxMacEditor >ObxMacEditor
  34.     Read "Oberon/F, Macintosh, Platform-Specific Issues" for more information about how to create Macintosh
  35.     standalone applications using Oberon/F.
  36.     IMPORT
  37.         SYSTEM,
  38.         MacTypes, QuickDraw := MacQuickDraw, MemoryMgr := MacMemoryMgr, FileMgr := MacFileMgr,
  39.         FontMgr := MacFontMgr, MenuMgr := MacMenuMgr, WindowMgr := MacWindowMgr,
  40.         TextEdit := MacTextEdit, DialogMgr := MacDialogMgr, PrintingMgr := MacPrintingMgr,
  41.         ControlMgr := MacControlMgr, EventMgr := MacEventMgr, DeskMgr := MacDeskMgr,
  42.         OSUtils := MacOSUtils, GestaltMgr := MacGestaltMgr;
  43.     CONST
  44.         UNTAGGED = 1;
  45.         CALLBACK = 2;
  46.         (* Apple menu *)
  47.         mApple = 256; 
  48.         iAbout = 1;
  49.         (* File menu *)
  50.         mFile = 257; 
  51.         iNew = 1;
  52.         iOpen = 2;
  53.         iClose = 3;
  54.         iSave = 5;
  55.         iPageSetUp = 7;
  56.         iPrint = 8;
  57.         iQuit = 10;
  58.         (* Edit menu *)
  59.         mEdit = 258;
  60.         iCut = 3;
  61.         iCopy = 4;
  62.         iPaste = 5;
  63.         iClear = 6;
  64.         iSelectAll = 8;
  65.         (* Font and Size menus *)
  66.         mFont = 259;
  67.         mSize = 260;
  68.         (* alerts *)
  69.         aAbout = 1000;
  70.         (* controls *)
  71.         rVScroll = 128;
  72.     TYPE
  73.         DocRec = RECORD [UNTAGGED]        (* data type for our documents *)
  74.             data : TextEdit.TEHandle;
  75.             vScrollBar : ControlMgr.ControlHandle
  76.         END;
  77.         DocPtr = POINTER TO DocRec;
  78.         wcount: SHORTINT;    (* application window number *)
  79.         gPrint : PrintingMgr.THPrint;    (* global print handle *)
  80.     (* two general routines for adjusting rectangles of the text windows *)
  81.     PROCEDURE GetTERect (window : WindowMgr.WindowPtr; VAR teRect : QuickDraw.Rect);
  82.     BEGIN
  83.         teRect := window.portRect;
  84.         QuickDraw.InsetRect(teRect, 4 ,4 );
  85.         DEC(teRect.right, 15);
  86.         DEC(teRect.bottom, 15)
  87.     END GetTERect;
  88.     PROCEDURE AdjustViewRect (docTE : TextEdit.TEHandle);
  89.     BEGIN
  90.         docTE.viewRect.bottom := (((docTE.viewRect.bottom - docTE.viewRect.top) DIV docTE.lineHeight) *
  91.             docTE.lineHeight) + docTE.viewRect.top
  92.     END AdjustViewRect;
  93.     (* creates and returns a new TextEdit window *)
  94.     PROCEDURE NewWindow () : WindowMgr.WindowPtr;
  95.         VAR 
  96.             winTitle: MacTypes.Str255;
  97.             wbounds, tbounds: QuickDraw.Rect;
  98.             window: WindowMgr.WindowPtr;
  99.             text: TextEdit.TEHandle;
  100.             newDoc : DocPtr;
  101.             info : FontMgr.FontInfo;
  102.     BEGIN
  103.         (* open new window *)
  104.         wbounds.top :=  QuickDraw.globals.screenBits.bounds.top + 40 + 10 * (wcount MOD 10);
  105.         wbounds.left := QuickDraw.globals.screenBits.bounds.left + 20 + 10 * (wcount MOD 10);
  106.         wbounds.bottom := QuickDraw.globals.screenBits.bounds.bottom - 20;
  107.         wbounds.right :=  QuickDraw.globals.screenBits.bounds.right-50; INC(wcount);
  108.         winTitle[0] := 3X; winTitle[1] := 23X; winTitle[2] := CHR((wcount DIV 10) MOD 10 + 30H);
  109.         winTitle[3] := CHR(wcount MOD 10 + 30H);
  110.         window := WindowMgr.NewWindow(NIL, wbounds, winTitle, FALSE, 0,
  111.                                                             SYSTEM.VAL(WindowMgr.WindowPtr, -1), TRUE, 0);
  112.         QuickDraw.SetPort(window);
  113.         GetTERect(window, tbounds);
  114.         text :=  TextEdit.TENew(tbounds, tbounds);    (* Add textedit structure and set default font *)
  115.         text.txFont := 4; text.txSize := 9;
  116.         QuickDraw.TextFont(4); QuickDraw.TextSize(9);
  117.         FontMgr.GetFontInfo(info);
  118.         text.lineHeight := info.ascent + info.descent + info.leading;
  119.         text.fontAscent := info.ascent;
  120.         AdjustViewRect(text);
  121.         TextEdit.TEAutoView(TRUE, text);        
  122.         newDoc  :=  SYSTEM.VAL(DocPtr, MemoryMgr.NewPtrClear(SIZE(DocRec)));
  123.         newDoc.data := text;
  124.         newDoc.vScrollBar := ControlMgr.GetNewControl(rVScroll, window);    (* add scrollbar *)
  125.         window.refCon := SYSTEM.VAL(LONGINT, newDoc);    (* we use the window refcon to store our data pointer *)
  126.         RETURN window
  127.     END NewWindow;
  128.     (* routines for text scrolling and updating *)
  129.     PROCEDURE AdjustTE (window : WindowMgr.WindowPtr);
  130.         VAR myDoc : DocPtr;
  131.     BEGIN
  132.         myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  133.         TextEdit.TEPinScroll(myDoc.data.viewRect.left - myDoc.data.destRect.left,
  134.             myDoc.data.viewRect.top - myDoc.data.destRect.top -
  135.             ControlMgr.GetCtlValue(myDoc.vScrollBar)*myDoc.data.lineHeight, myDoc.data)
  136.     END AdjustTE;
  137.     PROCEDURE AdjustScrollSizes (window : WindowMgr.WindowPtr);
  138.         VAR
  139.             myDoc : DocPtr;
  140.             teTop, teRight, teBottom : INTEGER;
  141.             teRect : QuickDraw.Rect;
  142.     BEGIN
  143.         myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  144.         GetTERect(window, teRect);
  145.         teTop := window.portRect.top;
  146.         teRight := window.portRect.right;
  147.         teBottom := window.portRect.bottom;
  148.         myDoc.data.viewRect := teRect;
  149.         AdjustViewRect(myDoc.data);
  150.         ControlMgr.MoveControl(myDoc.vScrollBar, teRight - 15, -1);
  151.         ControlMgr.SizeControl(myDoc.vScrollBar, 16, (teBottom-teTop) - 13)
  152.     END AdjustScrollSizes;
  153.     PROCEDURE AdjustScrollValues (window : WindowMgr.WindowPtr);
  154.         VAR 
  155.             myDoc : DocPtr;
  156.             max, lines, value : INTEGER;
  157.     BEGIN
  158.         myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  159.         lines := myDoc.data.nLines;
  160.         max := lines - ((myDoc.data.viewRect.bottom - myDoc.data.viewRect.top) DIV myDoc.data.lineHeight);
  161.         IF max < 0 THEN max := 0 END;
  162.         ControlMgr.SetCtlMax(myDoc.vScrollBar, max);
  163.         value := (myDoc.data.viewRect.top - myDoc.data.destRect.top) DIV myDoc.data.lineHeight;
  164.         IF value < 0 THEN value := 0 END;IF value > max THEN value := max END;
  165.         ControlMgr.SetCtlValue(myDoc.vScrollBar, value);
  166.         ControlMgr.ShowControl(myDoc.vScrollBar)
  167.     END AdjustScrollValues;
  168.     PROCEDURE AdjustScrollBars (window : WindowMgr.WindowPtr; resize : BOOLEAN);
  169.         VAR myDoc : DocPtr;
  170.     BEGIN
  171.         myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  172.         myDoc.vScrollBar.contrlVis := 0X;
  173.         IF resize THEN AdjustScrollSizes(window) END;
  174.         AdjustScrollValues(window)
  175.     END AdjustScrollBars;
  176.     (* use StandardGetFile to select and open a plain ascii text file *)
  177.     PROCEDURE OpenFile;
  178.         VAR
  179.             myTypes : FileMgr.SFTypeList;
  180.             myReply : FileMgr.StandardFileReply;
  181.             window : WindowMgr.WindowPtr;
  182.             inFile : INTEGER;
  183.             err : INTEGER;
  184.             theSize : LONGINT;
  185.             buffer : MacTypes.Ptr;
  186.             myDoc : DocPtr;
  187.     BEGIN
  188.         myTypes[0] := 054455854H;    (* TEXT *)
  189.         FileMgr.StandardGetFile(NIL, 1, myTypes, myReply);
  190.         IF myReply.sfGood THEN
  191.             window := NewWindow();
  192.             myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  193.             WindowMgr.SetWTitle(window, SYSTEM.VAL(MacTypes.Str255, myReply.sfFile.name));
  194.             err := FileMgr.FSpOpenDF(myReply.sfFile, 0, inFile);
  195.             err := FileMgr.GetEOF(inFile, theSize);
  196.             IF theSize > 7FFFH THEN theSize := 7FFFH END;    (* limitation of TextEdit, max 32768 chars *)
  197.             err := FileMgr.SetFPos(inFile, 1, 0);
  198.             buffer  :=  MemoryMgr.NewPtr(8000H);
  199.             err := FileMgr.FSRead(inFile, theSize, buffer);
  200.             err := FileMgr.FSClose(inFile);
  201.             TextEdit.TESetText(buffer, theSize, myDoc.data);
  202.             AdjustScrollBars(window, TRUE);
  203.             AdjustTE(window);
  204.             WindowMgr.ShowWindow(window);
  205.             MemoryMgr.DisposPtr(buffer)
  206.         END
  207.     END OpenFile;
  208.     (* close the front window *)
  209.     PROCEDURE CloseWindow;
  210.         VAR
  211.             window : WindowMgr.WindowPtr;
  212.             myDoc : DocPtr;
  213.     BEGIN
  214.         window := WindowMgr.FrontWindow();
  215.         IF window=NIL THEN RETURN END;
  216.         myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  217.         TextEdit.TEDispose(myDoc.data);
  218.         WindowMgr.CloseWindow(window);
  219.         MemoryMgr.DisposPtr(SYSTEM.VAL(MacTypes.Ptr, myDoc))
  220.     END CloseWindow;
  221.     (* save the contents of the front window to a file *)
  222.     PROCEDURE SaveWindow;
  223.         VAR
  224.             myReply : FileMgr.StandardFileReply;
  225.             prompt, defname : MacTypes.Str255;
  226.             myDoc : DocPtr;
  227.             window : WindowMgr.WindowPtr;
  228.             myFile : INTEGER;
  229.             err : INTEGER;
  230.             size : LONGINT;
  231.     BEGIN
  232.         window := WindowMgr.FrontWindow();
  233.         IF window = NIL THEN RETURN END;
  234.         MacTypes.SetStr255(prompt, 'Save file as :');
  235.         MacTypes.SetStr255(defname, 'Untitled');
  236.         FileMgr.StandardPutFile(prompt, defname, myReply);    (* select a file name *)
  237.         IF myReply.sfGood THEN
  238.             IF myReply.sfReplacing THEN err := FileMgr.FSpDelete(myReply.sfFile) END;
  239.             myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  240.             err := FileMgr.FSpCreate(myReply.sfFile, 045444954H, 054455854H, 0);    (* create a new file *)
  241.             err := FileMgr.FSpOpenDF(myReply.sfFile, 0, myFile);
  242.             IF err = 0 THEN
  243.                 (* write the text data *)
  244.                 size := myDoc.data.teLength;
  245.                 err := FileMgr.FSWrite(myFile, size, SYSTEM.VAL(MacTypes.Ptr, SYSTEM.ADR(myDoc.data.hText[0])));
  246.                 err := FileMgr.FSClose(myFile)
  247.             END
  248.         END
  249.     END SaveWindow;
  250.     (* print the contents of the front window *)
  251.     PROCEDURE DoPageSetUp;
  252.         VAR  ignore : BOOLEAN;
  253.     BEGIN
  254.         PrintingMgr.PrOpen;
  255.         ignore := PrintingMgr.PrStlDialog(gPrint);    (* get page setup *)
  256.         PrintingMgr.PrClose
  257.     END DoPageSetUp;
  258.     PROCEDURE DoPrint;
  259.         VAR
  260.             myDoc : DocPtr;
  261.             window : WindowMgr.WindowPtr;
  262.             pages : INTEGER;
  263.             lines : INTEGER;
  264.             prPort : PrintingMgr.TPPrPort;
  265.             line, page : INTEGER;
  266.             lh, y : INTEGER;
  267.     BEGIN
  268.         window := WindowMgr.FrontWindow();
  269.         IF window=NIL THEN RETURN END;
  270.         myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  271.         PrintingMgr.PrOpen;
  272.         IF PrintingMgr.PrJobDialog(gPrint) THEN    (* get printing options *)
  273.             prPort := PrintingMgr.PrOpenDoc(gPrint, NIL, NIL);
  274.             lines :=  (prPort.portRect.bottom - prPort.portRect.top) DIV myDoc.data.lineHeight;
  275.             pages :=  myDoc.data.nLines DIV lines;
  276.             line := 0; page := 0;
  277.             WHILE page <= pages DO
  278.                 PrintingMgr.PrOpenPage(prPort, NIL);
  279.                 QuickDraw.TextFont(myDoc.data.txFont);
  280.                 QuickDraw.TextSize(myDoc.data.txSize);
  281.                 lh := myDoc.data.lineHeight;
  282.                 y := lh;
  283.                 REPEAT
  284.                     QuickDraw.MoveTo(20,y);
  285.                     QuickDraw.DrawText(SYSTEM.ADR(myDoc.data.hText[0]), myDoc.data.lineStarts[line],
  286.                         myDoc.data.lineStarts[line + 1] - myDoc.data.lineStarts[line] - 1);
  287.                     INC(line);
  288.                     INC(y, lh)
  289.                 UNTIL ((line > myDoc.data.nLines) OR ((line MOD lines) = 0));
  290.                 PrintingMgr.PrClosePage(prPort);
  291.                 INC(page)
  292.             END;
  293.             PrintingMgr.PrCloseDoc(prPort)
  294.         END;
  295.         PrintingMgr.PrClose
  296.     END DoPrint;
  297.     (* clickroutine for scrollbar *)
  298.     PROCEDURE [CALLBACK] VertAction(control : ControlMgr.ControlHandle; part : INTEGER);
  299.         VAR
  300.             scrollDistance:INTEGER;
  301.             window : WindowMgr.WindowPtr;
  302.             myDoc : DocPtr;
  303.             oldSetting, max : INTEGER;
  304.     BEGIN
  305.         IF part # 0 THEN
  306.             window := control.contrlOwner;
  307.             myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  308.             CASE part OF
  309.             | ControlMgr.inUpButton,ControlMgr.inDownButton : scrollDistance := 1
  310.             | ControlMgr.inPageUp,ControlMgr.inPageDown : scrollDistance := 10
  311.             END;
  312.             IF (part = ControlMgr.inDownButton) OR (part = ControlMgr.inPageDown) THEN
  313.                 scrollDistance := -scrollDistance
  314.             END;
  315.             oldSetting := ControlMgr.GetCtlValue(control);
  316.             max := ControlMgr.GetCtlMax(control);
  317.             scrollDistance := oldSetting - scrollDistance;
  318.             IF scrollDistance < 0 THEN scrollDistance := 0 END;
  319.             IF scrollDistance > max THEN scrollDistance := max END;
  320.             ControlMgr.SetCtlValue(control, scrollDistance);
  321.             scrollDistance := oldSetting - scrollDistance;
  322.             IF scrollDistance # 0 THEN TextEdit.TEPinScroll(0, scrollDistance*myDoc.data.lineHeight, myDoc.data) END
  323.         END;
  324.     END VertAction;
  325.     (* process the clicking into a text window *)
  326.     PROCEDURE DoContentClick(window : WindowMgr.WindowPtr; event : EventMgr.EventRecord);
  327.         VAR
  328.             control : ControlMgr.ControlHandle;
  329.             value,part : INTEGER;
  330.             myDoc : DocPtr;
  331.             teRect : QuickDraw.Rect;
  332.     BEGIN
  333.         QuickDraw.SetPort(window);
  334.         QuickDraw.GlobalToLocal(event.where);
  335.         GetTERect(window, teRect);
  336.         myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  337.         IF ~QuickDraw.PtInRect(event.where, teRect) THEN    (* click into scrollbar? *)
  338.             part := ControlMgr.FindControl(event.where, window, control);
  339.             CASE part OF
  340.             | 0 :
  341.             | ControlMgr.inThumb : 
  342.                 value := ControlMgr.GetCtlValue(control);
  343.                 part := ControlMgr.TrackControl(control, event.where, NIL);
  344.                 IF part # 0 THEN
  345.                     value := value - ControlMgr.GetCtlValue(control);
  346.                     IF value # 0 THEN TextEdit.TEPinScroll(0, value*myDoc.data.lineHeight, myDoc.data) END
  347.                 END
  348.             ELSE 
  349.                 part  :=  ControlMgr.TrackControl(control, event.where, SYSTEM.VAL(MacTypes.ProcPtr, SYSTEM.ADR(VertAction)));
  350.             END
  351.         ELSE
  352.             TextEdit.TEClick(event.where, FALSE, myDoc.data)
  353.         END    (* click into window *)
  354.     END DoContentClick;
  355.     (* process the selection of a menu item *)
  356.     PROCEDURE MenuCommand (menuResult: LONGINT);    (* item has been chosen by MenuSelect or MenuKey *)
  357.         VAR 
  358.             menu, item: INTEGER;
  359.             Name: MacTypes.Str255;
  360.             daRefNum: INTEGER; 
  361.             itemHit: INTEGER; 
  362.             window: WindowMgr.WindowPtr;
  363.             myDoc: DocPtr; 
  364.             fontID, fsize : INTEGER; 
  365.             fInfo : FontMgr.FontInfo; 
  366.             oldPort : QuickDraw.GrafPtr;
  367.     BEGIN
  368.         (* get menu and item number *)
  369.         menu := SHORT(menuResult DIV 10000H); item := SHORT(menuResult MOD 10000H);
  370.         window := WindowMgr.FrontWindow();
  371.         IF window # NIL THEN myDoc := SYSTEM.VAL(DocPtr, window.refCon) END;
  372.         CASE menu OF
  373.         | mApple:
  374.             IF item=iAbout THEN
  375.                 itemHit := DialogMgr.Alert(aAbout, NIL)
  376.             ELSE
  377.                 MenuMgr.GetItem(MenuMgr.GetMHandle(mApple), item, Name);
  378.                 daRefNum := DeskMgr.OpenDeskAcc(Name)
  379.             END
  380.         | mFile:
  381.             CASE item OF
  382.             | iNew:
  383.                 window := NewWindow();AdjustScrollBars(window, TRUE);
  384.                 WindowMgr.ShowWindow(window)
  385.             | iOpen : OpenFile
  386.             | iClose : CloseWindow
  387.             | iPageSetUp : DoPageSetUp
  388.             | iPrint : DoPrint
  389.             | iSave : SaveWindow
  390.             | iQuit : OSUtils.ExitToShell 
  391.             ELSE
  392.             END
  393.         | mEdit:
  394.             IF window # NIL THEN
  395.                 CASE item OF    (* we don't exchange our data with the clipboard *)
  396.                 | iCut : TextEdit.TECut(myDoc.data)
  397.                 | iCopy : TextEdit.TECopy(myDoc.data)
  398.                 | iPaste : TextEdit.TEPaste(myDoc.data)
  399.                 | iClear : TextEdit.TEDelete(myDoc.data)
  400.                 | iSelectAll : TextEdit.TESetSelect(0, 32767, myDoc.data)
  401.                 ELSE
  402.                 END;
  403.                 AdjustScrollBars(window, FALSE)
  404.             END
  405.         | mFont:
  406.             IF window # NIL THEN
  407.                 MenuMgr.GetItem(MenuMgr.GetMHandle(mFont), item, Name);
  408.                 FontMgr.GetFNum(Name, fontID);
  409.                 QuickDraw.GetPort(oldPort);
  410.                 QuickDraw.SetPort(myDoc.data.inPort);
  411.                 QuickDraw.TextFont(fontID);
  412.                 myDoc.data.txFont := fontID;
  413.                 AdjustScrollBars(window, TRUE);
  414.                 AdjustTE(window);
  415.                 WindowMgr.InvalRect(window.portRect);
  416.                 QuickDraw.SetPort(oldPort)
  417.             END
  418.         | mSize:
  419.             IF window # NIL THEN
  420.                 CASE item OF
  421.                 | 1 : fsize := 9
  422.                 | 2 : fsize := 10
  423.                 | 3 : fsize := 12
  424.                 | 4 : fsize := 18
  425.                 | 5 : fsize := 24
  426.                 ELSE
  427.                 END;
  428.                 QuickDraw.GetPort(oldPort);
  429.                 QuickDraw.SetPort(myDoc.data.inPort);
  430.                 QuickDraw.TextSize(fsize);
  431.                 myDoc.data.txSize := fsize;
  432.                 FontMgr.GetFontInfo(fInfo);
  433.                 myDoc.data.lineHeight := fInfo.ascent + fInfo.descent + fInfo.leading;
  434.                 myDoc.data.fontAscent := fInfo.ascent;
  435.                 AdjustScrollBars(window, TRUE);
  436.                 AdjustTE(window);
  437.                 WindowMgr.InvalRect(window.portRect);
  438.                 QuickDraw.SetPort(oldPort)
  439.             END
  440.         ELSE
  441.         END;
  442.         MenuMgr.HiliteMenu(0)
  443.     END MenuCommand;
  444.     (* auxiliary routine for update *)
  445.     PROCEDURE GetLocalUpdateRgn (window : WindowMgr.WindowPtr; localRgn : QuickDraw.RgnHandle);
  446.     BEGIN
  447.         QuickDraw.CopyRgn(window.updateRgn, localRgn);
  448.         QuickDraw.OffsetRgn(localRgn, window.portPixMap.bounds.left, window.portPixMap.bounds.top)
  449.     END GetLocalUpdateRgn;
  450.     (* handle activating or deactivating of a text window  *)
  451.     PROCEDURE DoActivate (window : WindowMgr.WindowPtr; active : BOOLEAN);
  452.         VAR
  453.             myDoc : DocPtr;
  454.             growRect : QuickDraw.Rect;
  455.     BEGIN
  456.         myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  457.         IF active THEN
  458.             TextEdit.TEActivate(myDoc.data);
  459.             myDoc.vScrollBar.contrlVis := 0FFX;
  460.             WindowMgr.InvalRect(myDoc.vScrollBar.contrlRect);
  461.             growRect := window.portRect;
  462.             growRect.left := growRect.right-15;
  463.             growRect.top := growRect.bottom-15;
  464.             WindowMgr.InvalRect(growRect)
  465.         ELSE
  466.             TextEdit.TEDeactivate(myDoc.data);
  467.             ControlMgr.HideControl(myDoc.vScrollBar);
  468.             WindowMgr.DrawGrowIcon(window)
  469.         END
  470.     END DoActivate;
  471.     (* main loop of our program - handles all incoming events *)
  472.     PROCEDURE Loop;
  473.         VAR 
  474.             gotEvent: BOOLEAN;
  475.             event: EventMgr.EventRecord; 
  476.             window: WindowMgr.WindowPtr;
  477.             key: INTEGER;
  478.             newsize : LONGINT;
  479.             myDoc : DocPtr;
  480.             growRect, oldViewRect : QuickDraw.Rect;
  481.             locUpdateRgn : QuickDraw.RgnHandle;
  482.             theResult : BOOLEAN;
  483.     BEGIN
  484.         LOOP
  485.             gotEvent := EventMgr.WaitNextEvent(EventMgr.everyEvent, event, 0, NIL);
  486.             CASE event.what OF
  487.             | EventMgr.mouseDown:
  488.                 CASE WindowMgr.FindWindow(event.where, window) OF
  489.                 | WindowMgr.inMenuBar:
  490.                     MenuCommand(MenuMgr.MenuSelect(event.where))
  491.                 | WindowMgr.inSysWindow:
  492.                     DeskMgr.SystemClick(event, window)
  493.                 | WindowMgr.inContent:
  494.                     IF window # WindowMgr.FrontWindow() THEN
  495.                         WindowMgr.SelectWindow(window)
  496.                     ELSE
  497.                         DoContentClick(window, event)
  498.                     END
  499.                 | WindowMgr.inDrag:
  500.                     WindowMgr.DragWindow(window, event.where, QuickDraw.globals.screenBits.bounds)
  501.                 | WindowMgr.inGoAway:
  502.                     IF WindowMgr.TrackGoAway(window, event.where) THEN WindowMgr.CloseWindow(window) END
  503.                 | WindowMgr.inGrow: 
  504.                     QuickDraw.SetPort(window);
  505.                     QuickDraw.SetRect(growRect, 64, 64, 2000, 2000);
  506.                     newsize := WindowMgr.GrowWindow(window, event.where, growRect);
  507.                     IF newsize # 0 THEN
  508.                         myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  509.                         oldViewRect := myDoc.data.viewRect;
  510.                         locUpdateRgn := QuickDraw.NewRgn();
  511.                         GetLocalUpdateRgn(window, locUpdateRgn);
  512.                         WindowMgr.SizeWindow(window, SHORT(newsize MOD 10000H),
  513.                                                             SHORT(newsize DIV 10000H),TRUE);
  514.                         AdjustScrollBars(window, TRUE);
  515.                         AdjustTE(window);
  516.                         WindowMgr.InvalRect(window.portRect);
  517.                         theResult := QuickDraw.SectRect(oldViewRect, myDoc.data.viewRect, oldViewRect);
  518.                         WindowMgr.ValidRect(oldViewRect);
  519.                         WindowMgr.InvalRgn(locUpdateRgn);
  520.                         QuickDraw.DisposeRgn(locUpdateRgn)
  521.                     END
  522.                 | WindowMgr.inDesk, WindowMgr.inZoomIn, WindowMgr.inZoomOut:
  523.                 END
  524.             | EventMgr.keyDown, EventMgr.autoKey:    (* check if cmdkey is pressed *)
  525.                 key := SHORT(event.message MOD 100H);
  526.                 IF 8 IN SYSTEM.VAL(SET, LONG(event.modifiers)) THEN
  527.                     MenuCommand(MenuMgr.MenuKey(key))
  528.                 ELSE
  529.                     window := WindowMgr.FrontWindow();
  530.                     myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  531.                     TextEdit.TEKey(key, myDoc.data);    (* Enter key in text *)
  532.                     AdjustScrollBars(window, FALSE)
  533.                 END
  534.             | EventMgr.updateEvt:
  535.                 window := SYSTEM.VAL(WindowMgr.WindowPtr, event.message);
  536.                 IF window # NIL THEN
  537.                     myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  538.                     WindowMgr.BeginUpdate(window);
  539.                         QuickDraw.SetPort(window);
  540.                         QuickDraw.EraseRect(window.portRect);
  541.                         ControlMgr.DrawControls(window);
  542.                         WindowMgr.DrawGrowIcon(window);
  543.                         TextEdit.TEUpdate(window.portRect, myDoc.data);
  544.                     WindowMgr.EndUpdate(window)
  545.                 END
  546.             | EventMgr.activateEvt:    (* modifiers: bit0:  0 = deactivate 1 = activate *)
  547.                 window := SYSTEM.VAL(WindowMgr.WindowPtr, event.message);
  548.                 IF window # NIL THEN DoActivate(window, ODD(event.modifiers)) END
  549.             | EventMgr.osEvt:
  550.                 window := WindowMgr.FrontWindow();
  551.                 IF window # NIL THEN
  552.                     myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  553.                     IF SYSTEM.LSH(event.message, -24) (*MOD 100H*)=EventMgr.suspendResumeMessage THEN
  554.                         IF ODD(event.message) THEN    (* activate *)
  555.                             QuickDraw.SetPort(window); TextEdit.TEActivate(myDoc.data); QuickDraw.InitCursor
  556.                         ELSE    (* deactivate *)
  557.                             TextEdit.TEDeactivate(myDoc.data); QuickDraw.InitCursor
  558.                         END
  559.                     END
  560.                 ELSE QuickDraw.InitCursor
  561.                 END
  562.             | EventMgr.nullEvent:
  563.                 window := WindowMgr.FrontWindow();
  564.                 IF window # NIL THEN
  565.                     myDoc := SYSTEM.VAL(DocPtr, window.refCon);
  566.                     TextEdit.TEIdle(myDoc.data)
  567.                 END
  568.             ELSE    (* ignore other event types *)
  569.             END
  570.         END
  571.     END Loop;
  572.     (* Initalize all menus, variables etc  *)
  573.     PROCEDURE InitMac;
  574.         VAR systemversion : LONGINT; res: MacTypes.OSErr;
  575.     BEGIN
  576.         MemoryMgr.MaxApplZone;
  577.         MemoryMgr.MoreMasters;
  578.         QuickDraw.InitGraf(QuickDraw.globals.thePort);
  579.         (* The QuickDraw Globals are proper Oberon Variables *)
  580.         FontMgr.InitFonts;
  581.         WindowMgr.InitWindows;
  582.         MenuMgr.InitMenus;
  583.         TextEdit.TEInit;
  584.         DialogMgr.InitDialogs(0);
  585.         QuickDraw.InitCursor;
  586.         EventMgr.FlushEvents(EventMgr.everyEvent, 0);
  587.         res  :=  GestaltMgr.Gestalt(GestaltMgr.SystemVersion, systemversion);
  588.         IF (res # 0) OR (systemversion < 0700H) THEN
  589.             OSUtils.SysBeep(1);
  590.             OSUtils.ExitToShell
  591.         END;
  592.         (* set up menus *)
  593.         MenuMgr.SetMenuBar(MenuMgr.GetNewMBar(128));    
  594.         MenuMgr.AddResMenu(MenuMgr.GetMHandle(mApple), 44525652H);
  595.         MenuMgr.AddResMenu(MenuMgr.GetMHandle(mFont), 464F4E54H);
  596.         MenuMgr.DrawMenuBar;
  597.         (* set up print structure *)
  598.         gPrint  :=  SYSTEM.VAL(PrintingMgr.THPrint, MemoryMgr.NewHandle(120));
  599.         PrintingMgr.PrOpen;
  600.         PrintingMgr.PrintDefault(gPrint);
  601.         PrintingMgr.PrClose
  602.     END InitMac;
  603. BEGIN
  604.     InitMac;
  605.     Loop
  606. END ObxMacEditor.
  607. TextControllers.StdCtrlDesc
  608. TextControllers.ControllerDesc
  609. Containers.ControllerDesc
  610. Controllers.ControllerDesc
  611. Helvetica
  612. Documents.ControllerDesc
  613.